/*
 *  Copyright 2010 Andrew Kroh
 *
 *  Kroh-IO is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Kroh-IO is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package kroh.io;

import java.util.EventObject;

/**
 * A serial port event.
 */
public class SerialPortEvent extends EventObject
{
    public static final int DATA_AVAILABLE = 1;
    public static final int OUTPUT_BUFFER_EMPTY = 2;
    public static final int CTS = 3;
    public static final int DSR = 4;
    public static final int RI = 5;
    public static final int CD = 6;
    public static final int OE = 7;
    public static final int PE = 8;
    public static final int FE = 9;
    public static final int BI = 10;

    private final int eventType;
    private final boolean oldValue;
    private final boolean newValue;

    /**
     * Constructs a SerialPortEvent with the specified serial port, event type,
     * old and new values. Application programs should not directly create
     * SerialPortEvent objects.
     * 
     * @param srcport
     *            source serial port
     * @param eventtype
     *            event type
     * @param oldvalue
     *            old value
     * @param newvalue
     *            new value
     */
    public SerialPortEvent(SerialPort srcport, int eventtype, boolean oldvalue,
            boolean newvalue)
    {
        super(srcport);

        this.oldValue = oldvalue;
        this.newValue = newvalue;
        this.eventType = eventtype;
    }

    /**
     * Gets the type of this event.
     * 
     * @return integer that can be equal to one of the following static
     *         variables: BI, CD, CTS, DATA_AVAILABLE, DSR, FE, OE,
     *         OUTPUT_BUFFER_EMPTY, PE or RI.
     */
    public int getEventType()
    {
        return eventType;
    }

    /**
     * Gets the new value of the state change that caused the SerialPortEvent to
     * be propagated. For example, when the CD bit changes, newValue reflects
     * the new value of the CD bit.
     * 
     * @return the new value
     */
    public boolean getNewValue()
    {
        return newValue;
    }

    /**
     * Gets the old value of the state change that caused the SerialPortEvent to
     * be propagated. For example, when the CD bit changes, oldValue reflects
     * the old value of the CD bit.
     * 
     * @return the old value
     */
    public boolean getOldValue()
    {
        return oldValue;
    }
    
    /**
     * Serial Version UID
     */
    private static final long serialVersionUID = -2738843970010078030L;
}
